<template>
  <div class="buy">
    <van-nav-bar fixed title="Buy" left-arrow :border="false" />
    <div class="header">
      <div class="title">A versão do pacote foi selecionada：</div>
      <div class="type">Versão avançada<van-icon name="arrow" color="#999" /></div>
    </div>
    <div class="types">
      <div class="flex">
        <div class="classify-col flex-none" v-for="item in 20" :key="item">
          <div class="classify-item flex flex-column flex-align-items-center flex-justify-content-center">
            <div class="type-img">
              <img :src="require('@/assets/images/type.png')" alt="" />
              <div class="checked" v-if="item % 4 === 0"><van-icon name="checked" /></div>
            </div>
            <span class="type-name">roupas</span>
          </div>
        </div>
      </div>
    </div>
    <div class="check-list p16">
      <div class="check-item flex flex-align-items-center p10" v-for="(item, index) in list" :key="index" @click="handleCheck(index)">
        <div class="check-info flex-auto width0 flex flex-column flex-justify-content-between">
          <div class="check-row"><span>Secção：</span>Este é o nome do campo. pode ser tã…</div>
          <div class="check-row"><span>Preços：</span>300 KZ</div>
          <div class="check-row"><span>Número preferencial de itens：</span>159</div>
        </div>
        <div class="flex-none ml10">
          <van-icon name="checked" size="22" color="#fb8c24" v-if="item.checked" />
          <van-icon name="circle" size="22" color="#595959" v-else />
        </div>
      </div>
    </div>
    <div class="total-bottom">
      <div>
        <span class="total-label">Preço total：</span>
        <span class="total-price">{{ totalMoney }} KZ</span>
      </div>
      <div>
        <cu-button :width="155" :height="44">Pagamentos</cu-button>
      </div>
    </div>
  </div>
</template>
<script>
import CuButton from '@/components/button';
export default {
  name: 'Buy',
  components: { CuButton },
  data() {
    return {
      list: [
        {
          price: 10,
          checked: false,
        },
        {
          price: 20,
          checked: true,
        },
      ],
    };
  },
  computed: {
    totalMoney() {
      let total = 0;
      this.list.forEach((item) => {
        if (item.checked) {
          console.log(item.price);
          total = ((parseFloat(total) * 100 + parseFloat(item.price) * 100) / 100).toFixed(2);
        }
      });
      return total;
    },
  },
  methods: {
    handleCheck(index) {
      this.$set(this.list, index, { ...this.list[index], checked: !this.list[index].checked });
    },
  },
};
</script>
<style lang="less" scoped>
.buy {
  padding-top: 62px;
  padding-bottom: 60px;
  .header {
    height: 58px;
    background: linear-gradient(90deg, #ffdfc7 0%, rgba(242, 242, 242, 0) 100%);
    padding: 0 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    .title {
      color: #333;
      font-weight: bold;
      font-size: 16px;
    }
    .type {
      margin-top: 5px;
      color: #fb8c24;
      font-weight: bold;
      font-size: 16px;
      display: flex;
      align-items: center;
    }
  }
  .types {
    overflow-x: auto;
    .classify-col {
      width: 100px;
      .classify-item {
        height: 120px;
        .type-img {
          width: 56px;
          height: 56px;
          border-radius: 100%;
          position: relative;
          .checked {
            position: absolute;
            left: 0;
            top: 0;
            width: 56px;
            height: 56px;
            border-radius: 100%;
            background: rgba(0, 0, 0, 0.3);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 24px;
          }
          img {
            width: 100%;
            height: 100%;
          }
        }
        .type-name {
          color: #595959;
          margin-top: 10px;
        }
      }
    }
  }
  .check-list {
    .check-item {
      height: 110px;
      border-radius: 4px;
      background: #fff;
      box-sizing: border-box;
      margin-bottom: 10px;
      .check-info {
        height: 100%;
        .check-row {
          color: #595959;
          font-size: 14px;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          span {
            color: #999;
          }
        }
      }
    }
  }
  .total-bottom {
    position: fixed;
    width: 100%;
    height: 60px;
    box-sizing: border-box;
    left: 0;
    bottom: 0;
    box-shadow: 0px -2px 4px rgba(0, 0, 0, 0.06);
    background: #fff;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .total-label {
      font-size: 12px;
      color: #999;
    }
    .total-price {
      color: #e94941;
      font-size: 18px;
      font-weight: bold;
      margin-left: 10px;
    }
  }
}
</style>
